package com.itheima.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itheima.domain.User;
import com.itheima.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sun.org.apache.regexp.internal.recompile;

public class UserAction extends ActionSupport  implements ModelDriven<User>{


	private User user = new User();
	@Override
	public User getModel() {
		// TODO Auto-generated method stub
		return user;
	}
	
	
	/*public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}*/

	private UserService service;

	public UserService getService() {
		return service;
	}


	public void setService(UserService service) {
		this.service = service;
	}
	
	//用户登录
	public String login() {
		System.out.println("user action。。。。");
		/*User user = new User();
		user.setUsername(request.getParameter("username"));
		user.setPassword(request.getParameter("password"));*/
		if (user != null) {
			user = service.login(user);
			if (user != null) {
				HttpServletRequest request = ServletActionContext.getRequest();
				request.getSession().setAttribute("user", user);
				return "index";
			}
		}
		return "login";
	}

	//用户退出
	public String exit() {
		ServletActionContext.getRequest().getSession().setAttribute("user", null);
		return "login";
	}



}
